package demo.practice.competition;

public class P5816 {
    //超时

    public static void main(String[] args) {
        P5816 p5816 = new P5816();
        p5816.maxGeneticDifference(new int[]{-1, 0, 1, 1}, new int[][]{{0, 2}, {3, 2}, {2, 5}});
    }

    public int[] maxGeneticDifference(int[] parents, int[][] queries) {


        if (parents == null || parents.length == 0 || queries == null || queries.length == 0) {
            return new int[0];
        }

        int[] res = new int[queries.length];

        int i = 0;
        for (int[] q : queries) {
            int v = q[0];
            int index = q[1];
            int maxXOR = index ^ v;

            while (v != -1) {
                v = parents[v];
                maxXOR = Math.max(maxXOR, index ^ v);
            }
            res[i] = maxXOR;
            i++;
        }

        return res;

    }


    class UF {
        int[] parent;

        public UF(int size) {

        }
    }

}


